import { request } from './reques'

// 地址相关类型定义
export interface Address {
  id?: string
  name: string
  phone: string
  city: string
  desc: string
  state: number // 0: 非默认, 1: 默认
}

export interface AddAddressParams {
  name: string
  phone: string
  city: string
  desc: string
  state: number
}

export interface UpdateAddressParams extends AddAddressParams {
  id: string
}

export interface AddressResponse {
  code: number
  message: string
  data: any
}

// 新增收货地址
export const addAddress = async (params: AddAddressParams): Promise<AddressResponse> => {
  return request.put('/address/add', params)
}

// 获取收货地址列表
export const getAddressList = async (): Promise<AddressResponse> => {
  return request.get('/address/list')
}

// 修改收货地址
export const updateAddress = async (params: UpdateAddressParams): Promise<AddressResponse> => {
  return request.post('/address/update', params)
}

// 删除收货地址
export const deleteAddress = async (id: string): Promise<AddressResponse> => {
  return request.delete(`/address/delete/${id}`)
}

// 修改默认地址
export const setDefaultAddress = async (id: string): Promise<AddressResponse> => {
  return request.post('/address/default', { id })
}
